from typing import Dict

from llama_index.llms.openai import OpenAI

from app.core.config import settings


from llama_index.llms.openai.utils import ALL_AVAILABLE_MODELS, CHAT_MODELS
# 定义模型及其对应的上下⽂⼤⼩
LLM_MODELS_CONF: Dict[str, int] = {
    "ishumilin/deepseek-r1-coder-tools:14b": 64000,#设置上下⽂⼤⼩为64000
    "qwen2.5-coder:7b": 131072,
    "qwen-max-latest": 64000,
}



def init_available_modules(model,content_length):
    if model not in ALL_AVAILABLE_MODELS:
        if model not in LLM_MODELS_CONF:
            LLM_MODELS_CONF[model] = content_length
        # 更新所有可⽤模型的字典，添加DeepSeeK模型
        ALL_AVAILABLE_MODELS.update(LLM_MODELS_CONF)
        # 更新聊天模型的字典，添加DeepSeeK模型
        CHAT_MODELS.update(LLM_MODELS_CONF)
def createOpenAI(
        model=settings.OPENAI_MODEL,
        api_base=settings.OPENAI_API_BASE,
        api_key=settings.OPENAI_API_KEY,
        content_length=64000,#设置上下⽂⼤⼩为64000,openai配置中没有该模型时使用
        temperature=0.7,
           ):
    init_available_modules(model,content_length)
    llm = OpenAI(model=model,
                 api_base=api_base,
                 api_key=api_key, temperature=temperature)
    return llm
